import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserModule } from './feature/user/user.module';
import { PostModule } from './feature/post/post.module';
import { AuthModule } from '@/core/auth/auth.module';
import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import { JwtAuthGuard } from '@/core/auth/jwt.auth.guard';
import { RoleModule } from './feature/role/role.module';
import { MenuModule } from './feature/menu/menu.module';
import { DictModule } from './feature/dict/dict.module';
import { PollModule } from './feature/poll/poll.module';
import { SingerModule } from '@/feature/singer/singer.module';
import { TimezoneInterceptor } from './core/middleware/custom-date.middleware';
import { FileUploadController } from './feature/file/file.controller';
import { CommentModule } from './feature/comment/comment.module';
import { PrefixMiddleware } from './core/middleware/prefix.middleware';
import { getMySqlConfig } from './config/mySql';
@Module({
  imports: [
    TypeOrmModule.forRoot(getMySqlConfig as any),
    AuthModule,
    UserModule,
    PostModule,
    RoleModule,
    MenuModule,
    DictModule,
    PollModule,
    SingerModule,
    CommentModule,
  ],
  controllers: [AppController, FileUploadController],
  providers: [
    AppService,
    // 启用全局身份校验
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: TimezoneInterceptor,
    },
  ],
})
export class AppModule {}
